package com.itheima.exam.interceptor;

import com.itheima.exam.constant.AppConstant;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否登陆
        //登陆 => 放行
        //没登陆 => 拦截
        return request.getSession().getAttribute(AppConstant.USER_INFO) != null;
    }

}
